/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice;

import org.proteusframework.core.api.model.IDisplayableName;
import org.proteusframework.core.base.AbstractStandardPlugin;

import java.util.ArrayList;
import java.util.List;

/**
 * Base class of all {@link IServicePlugin} instances.
 */
public abstract class AbstractServicePlugin extends AbstractStandardPlugin implements IServicePlugin
{
    private List<ServiceScope> restrictedServiceScopes = new ArrayList<ServiceScope>();

    /**
     * Defines a service plugin with no restricted scopes.
     *
     * @param dn    Displayable name of the service plugin
     * @param clazz Class that implements the service plugin
     */
    protected AbstractServicePlugin(IDisplayableName dn, Class clazz)
    {
        super(dn, clazz);
    }

    /**
     * Defines a service plugin with one or more restricted scopes.
     *
     * @param dn              Displayable name of the service plugin
     * @param clazz           Class that implements the service plugin
     * @param restrictedScope One or more restricted scopes that the plugin explicitly prohibits
     */
    protected AbstractServicePlugin(IDisplayableName dn, Class clazz, ServiceScope... restrictedScope)
    {
        super(dn, clazz);

        if (null != restrictedScope && restrictedScope.length > 0)
        {
            for (ServiceScope scope : restrictedScope)
            {
                if (null != scope)
                {
                    restrictedServiceScopes.add(scope);
                }
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final List<ServiceScope> getRestrictedServiceScopes()
    {
        return restrictedServiceScopes;
    }
}
